/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.excesys.exsecs.om.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.log.annotation.SysLog;
import com.excesys.exsecs.om.constans.OmCommonConstants;
import com.excesys.exsecs.om.dto.PlanDto;
import com.excesys.exsecs.om.entity.OmICheckPlan;
import com.excesys.exsecs.om.service.OmICheckPlanService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巡检计划表
 *
 * @author weiyj
 * @date 2023-03-01 14:10:58
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/omicheckplan")
@Tag(name = "巡检计划表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class OmICheckPlanController {

	private final OmICheckPlanService omICheckPlanService;

	/**
	 * 分页查询
	 * @param page 分页对象
	 * @param planDto 巡检计划表
	 * @return
	 */
	@Operation(summary = "分页查询", description = "分页查询")
	@GetMapping("/page")
	@PreAuthorize("@pms.hasPermission('om_omicheckplan_get')")
	public R getOmICheckPlanPage(Page page, PlanDto planDto) {
		return R.ok(omICheckPlanService.getPlanWithRelPage(page, planDto));
	}

	/**
	 * 通过id查询巡检计划表
	 * @param plId id
	 * @return R
	 */
	@Operation(summary = "通过id查询", description = "通过id查询")
	@GetMapping("/{plId}")
	@PreAuthorize("@pms.hasPermission('om_omicheckplan_get')")
	public R getById(@PathVariable("plId") Integer plId) {
		return R.ok(omICheckPlanService.getById(plId));
	}

	/**
	 * 新增巡检计划表
	 * @param planDto 巡检计划表
	 * @return R
	 */
	@Operation(summary = "新增巡检计划表", description = "新增巡检计划表")
	@SysLog("新增巡检计划表")
	@PostMapping
	@PreAuthorize("@pms.hasPermission('om_omicheckplan_add')")
	public R save(@RequestBody PlanDto planDto) {

		return R.ok(omICheckPlanService.savePlan(planDto));
	}

	/**
	 * 修改巡检计划表
	 * @param planDto 巡检计划表
	 * @return R
	 */
	@Operation(summary = "修改巡检计划表", description = "修改巡检计划表")
	@SysLog("修改巡检计划表")
	@PutMapping
	@PreAuthorize("@pms.hasPermission('om_omicheckplan_edit')")
	public R updateById(@RequestBody PlanDto planDto) {
		return R.ok(omICheckPlanService.updatePlan(planDto));
	}

	/**
	 * 通过id删除巡检计划表
	 * @param plId id
	 * @return R
	 */
	@Operation(summary = "通过id删除巡检计划表", description = "通过id删除巡检计划表")
	@SysLog("通过id删除巡检计划表")
	@DeleteMapping("/{plId}")
	@PreAuthorize("@pms.hasPermission('om_omicheckplan_del')")
	public R removeById(@PathVariable Integer plId) {
		OmICheckPlan omICheckPlan = omICheckPlanService.getById(plId);
		return R.ok(omICheckPlanService.removePlanById(omICheckPlan));
	}

	/**
	 * 列表查询
	 * @param planDto 巡检计划表
	 * @return
	 */
	@Operation(summary = "列表查询", description = "列表查询")
	@GetMapping("/list")
	// @PreAuthorize("@pms.hasPermission('om_omicheckroute_get')" )
	public R<List<OmICheckPlan>> getOmICheckRouteList(PlanDto planDto) {
		planDto.setDelFlag(OmCommonConstants.PLAN_TYPE_USE);
		return R.ok(omICheckPlanService.list(Wrappers.query(planDto)));
	}

	/**
	 * 删除多个投诉
	 * @param idList 删除多个投诉
	 * @return R
	 */
	@Operation(summary = "删除多个巡检计划", description = "删除多个巡检计划")
	@SysLog("删除多个巡检计划")
	@DeleteMapping("/removeByIds")
	@PreAuthorize("@pms.hasPermission('om_omicheckplan_del')")
	public R removeByIds(@RequestBody List<Integer> idList) {
		return R.ok(omICheckPlanService.removeByIds(idList));
	}

}
